jQuery(document).ready(function(){
		jQuery("ul.sf-menu").superfish(
			{
				onShow:function(){
						var scroll_window = jQuery('body').scrollTop();
						var view_port_height = jQuery(window).height();
						var scroll_bottom = scroll_window + view_port_height;
						var menu_top = jQuery(this).offset().top;
						var menu_height = jQuery(this).height();
						var menu_pos = menu_top + menu_height;

						if(menu_pos > scroll_bottom)
						{
							var moveTo = menu_height - 25;
							moveTo = '-'+moveTo+'px';
							jQuery(this).animate({top: moveTo}, 500);
							/*
							scroll_to = scroll_window + (menu_pos - scroll_bottom);
							scroll_to = parseInt(scroll_to);
							// use this if the current animate causes problems.
							//jQuery(window).scrollTop(scroll_to);
							jQuery('html,body').animate({scrollTop: scroll_to}, 500);
							*/
						}
					},
					onHide:function(){
						jQuery(this).animate({top: 0}, 500);
					}
			}
		);
		/*
		jQuery('ul.sf-menu').mouseover(function(){
			var scroll_window = jQuery('body').scrollTop();
			var view_port_height = jQuery(window).height();
			var scroll_bottom = scroll_window + view_port_height;
			var menu_top = jQuery(this).offset().top;
			var menu_height = jQuery(this).height();
			var menu_pos = menu_top + menu_height;
			
			if(menu_pos > scroll_bottom){
				var scroll_to = scroll_window + (menu_pos - scroll_bottom);
				scroll_to = parseInt(scroll_to);
				jQuery('html,body').animate({scrollTop: scroll_to}, 500);
			}
		});
		*/
	});
